﻿//-----------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Microsoft.WindowsAPICodePack;
using Microsoft.WindowsAPICodePack.Shell;
using System.Windows.Data;
using Microsoft.LibraryManagerDemo.Models;

namespace Microsoft.LibraryManagerDemo.Presenters
{
    /// <summary>
    /// Provides logic for picking a library template type.
    /// </summary>
    internal class LibraryTypePresenter : PresenterBase
    {
        #region Properties

        /// <summary>
        /// Gets a list folder templates.
        /// </summary>
        public IList<FolderTemplate> FolderTemplates { get; private set; }

        /// <summary>
        /// Gets the selected folder type.
        /// </summary>
        public LibraryFolderType FolderType { get; private set; }
        
        #endregion        

        #region Initializers

        /// <summary>
        /// Initializes a new instance of this type with shell library folder types..
        /// </summary>
        public LibraryTypePresenter()
        {
            FolderTemplates = new List<FolderTemplate>
            {
                new FolderTemplate() { Type = LibraryFolderType.Generic, Icon = new StockIcon(StockIconIdentifier.DocumentNotAssociated, StockIconSize.Large, false, false) },
                new FolderTemplate() { Type = LibraryFolderType.Documents, Icon = new StockIcon(StockIconIdentifier.DocumentAssociated, StockIconSize.Large, false, false) },
                new FolderTemplate() { Type = LibraryFolderType.Pictures, Icon = new StockIcon(StockIconIdentifier.ImageFiles, StockIconSize.Large, false, false) },
                new FolderTemplate() { Type = LibraryFolderType.Music, Icon = new StockIcon(StockIconIdentifier.AudioFiles, StockIconSize.ShellSize, false, false) },
                new FolderTemplate() { Type = LibraryFolderType.Videos, Icon = new StockIcon(StockIconIdentifier.VideoFiles, StockIconSize.Large, false, false) }
            };

            // Get te default folder template collection view and select the first folder template.
            var defaultView = CollectionViewSource.GetDefaultView(FolderTemplates);
            defaultView.MoveCurrentTo(FolderTemplates[0]);
            defaultView.CurrentChanged += defaultView_CurrentChanged;
        }
        
        #endregion

        #region Event Handlers

        void defaultView_CurrentChanged(object sender, EventArgs e)
        {
            var defaultView = CollectionViewSource.GetDefaultView(FolderTemplates);
            var folderTemplate = defaultView.CurrentItem as FolderTemplate;

            if (folderTemplate != null)
            {
                FolderType = folderTemplate.Type;
            }
        }
        
        #endregion
    }
}
